package com.frejoys.app.controller;

import com.frejoys.common.aop.Authority;
import com.frejoys.common.aop.Authorization;
import com.frejoys.common.constant.CommonConstant;
import com.frejoys.common.dto.common.IdDto;
import com.frejoys.common.dto.common.appversion.AppVersionAddDto;
import com.frejoys.common.dto.common.appversion.AppVersionInfoDto;
import com.frejoys.common.dto.common.appversion.AppVersionListDto;
import com.frejoys.common.response.Result;
import com.frejoys.common.vo.common.AppVersionVo;
import com.frejoys.dao.util.AppVersionVoUtil;
import com.frejoys.service.AppVersionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "app升级版本", description = "app升级版本")
@RestController
@RequiredArgsConstructor
@RequestMapping(CommonConstant.routePrefixApp)
@Authorization(Authority.Private)
public class AppVersionController {

    private final AppVersionService appVersionService;

    @Operation(summary = "添加版本")
    @PostMapping("/appVersion/add/info")
    public Result addInfo(@RequestBody @Validated AppVersionAddDto dto) {
        appVersionService.addInfo(dto);
        return Result.success();
    }

    @Operation(summary = "删除版本")
    @PostMapping("/appVersion/del/info")
    public Result delInfo(@RequestBody @Validated IdDto dto) {
        appVersionService.delInfo(dto);
        return Result.success();
    }

    @Operation(summary = "获取最新升级版本")
    @Authorization(Authority.Protected)
    @PostMapping("/appVersion/get/last/info")
    public Result<AppVersionVo> getLastInfo(@RequestBody @Validated AppVersionInfoDto dto) {
        return Result.success(AppVersionVoUtil.toVo(appVersionService.getLastInfo(dto)));
    }

    @Operation(summary = "获取版本列表")
    @PostMapping("/appVersion/list/info")
    public Result<List<AppVersionVo>> listInfo(@RequestBody @Validated AppVersionListDto dto) {
        return Result.success(AppVersionVoUtil.toVo(appVersionService.listInfo(dto)));
    }



}
